/*
 * @Date: 2023-01-24 19:25:18
 * @LastEditors: 恶名扬 2080156129@qq.com
 * @LastEditTime: 2023-01-24 20:01:24
 * @FilePath: \campus-repair-platform\web\src\router\index.js
 */
import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layout'

import announceSR from './modules/announcement/s_r'
import repairStudent from './modules/repair/student'
import repairRepairer from './modules/repair/repairer'
import recordRepairer from './modules/record'
import feedbackSR from './modules/feedback/sr_feedback'
import feedbackA from './modules/feedback/admin'
import announcementA from './modules/announcement/admin'
import user from './modules/admin'
import repairA from './modules/repair/admin'
import userA from './modules/user'
// import studentInfoA from './modules/admin/studen_info'
import systemInfoA from './modules/admin/system_info'
import repairRequestStudent from './modules/repair_request'

Vue.use(VueRouter)

// 动态路由表
export const asyncRouters = {
  1: [repairStudent, repairRequestStudent, announceSR, feedbackSR],
  2: [recordRepairer, repairRepairer, announceSR, feedbackSR],
  3: [repairA, feedbackA, announcementA, userA],
  4: [repairA, feedbackA, announcementA, user, systemInfoA]
}

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/'),
        meta: { title: '首页' }
      }
    ]
  },
  {
    path: '/personage',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/user/'),
        meta: { title: '个人信息' }
      },
      {
        path: 'password',
        component: () => import('@/views/user/password'),
        meta: { title: '修改密码' }
      }
    ],
    meta: { title: '个人中心' }
  }
]

const createRouter = () =>
  new VueRouter({
    mode: 'history', // require service support
    base: process.env.BASE_URL,
    routes: [...constantRoutes]
  })

const router = createRouter()

export function resetRouter () {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
